package com.eight.travel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.travel.dao.FoodMapper;
import com.eight.travel.pojo.FoodMp;
import com.eight.travel.pojo.Foodcomment;
import com.eight.travel.pojo.Foodrestaurant;
import com.eight.travel.service.FoodService;
import com.eight.travel.utils.BaseResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, FoodMp> implements FoodService {
    @Resource
    FoodMapper foodMapper;
    @Override
    public BaseResp findAllFood() {
        List<FoodMp> allFood = foodMapper.findAllFood();
        if (allFood.size()!=0)
            return new BaseResp().SUCCESS("查询成功",allFood,null);
        return new BaseResp().FAIL("没有数据");

    }
//根据fid查询餐厅
    @Override
    public BaseResp findrestByFid(int fid) {
        List<Foodrestaurant> allrestByFid = foodMapper.findrestByFid(fid);
        if (allrestByFid.size()!=0)
            return new BaseResp().SUCCESS("查询成功",allrestByFid,null);
        return new BaseResp().FAIL("没有数据");
    }

    @Override
    public BaseResp findByHot(int page,int size) {
        List<FoodMp> byHot = foodMapper.findByHot(page, size);
        List<FoodMp> allFood = foodMapper.findAllFood();
        System.out.println("allFood = " + allFood.size());
        if (byHot.size()!=0)
            return new BaseResp().SUCCESS("查询成功",byHot,allFood.size());
        return new BaseResp().FAIL("没有数据");

    }

    @Override
    public BaseResp findByPrice(int page,int size) {
        List<FoodMp> byPrice = foodMapper.findByPrice(page, size);
        List<FoodMp> allFood = foodMapper.findAllFood();
        System.out.println("allFood = " + allFood.size());
        if (byPrice.size()!=0)
            return new BaseResp().SUCCESS("查询成功",byPrice,allFood.size());
        return new BaseResp().FAIL("没有数据");
    }

    @Override
    public BaseResp findByName(String foodname) {
        List<FoodMp> byName = foodMapper.findByName(foodname);
        if (byName.size()!=0)
            return new BaseResp().SUCCESS("查询成功",byName,null);
        return new BaseResp().FAIL("没有数据");
    }

    @Override
    public BaseResp findByPage(int page,int size) {
        List<FoodMp> byPage = foodMapper.findByPage((page-1)*size,size);
        System.out.println("byPage = " + byPage);
        List<FoodMp> allFood = foodMapper.findAllFood();
        System.out.println("allFood = " + allFood.size());
        return new BaseResp().SUCCESS("成功",byPage,allFood.size());
    }

    @Override
    public BaseResp addHot(int fid) {
        int i = foodMapper.addHot(fid);
        if (i!=1)
            return new BaseResp().FAIL("失败");
        return new BaseResp().SUCCESS("成功",i,null);
    }

    @Override
    public BaseResp reduceHot(int fid) {
        int i = foodMapper.reduceHot(fid);
        if (i!=1)
            return new BaseResp().FAIL("失败");
        return new BaseResp().SUCCESS("成功",i,null);
    }

    @Override
    public BaseResp findByStatus() {
        List<Foodrestaurant> byStatus = foodMapper.findByStatus();
        if (byStatus.size()!=0)
            return new BaseResp().SUCCESS("cg",byStatus,null);
        return new BaseResp().FAIL("失败");

    }

    @Override
    public BaseResp addcomment(Foodcomment foodcomment) {
        int addcomment = foodMapper.addcomment(foodcomment);
        if (addcomment==1)
            return new BaseResp().SUCCESS("成功",addcomment,null);
        return new BaseResp().FAIL("失败");
    }

    @Override
    public BaseResp findconmmentByFaid(int faid) {
        List<Foodrestaurant> foodrestaurants = foodMapper.findconmmentByFaid(faid);
        if (foodrestaurants.size()!=0)
            return new BaseResp().SUCCESS("cg",foodrestaurants,null);

        return new BaseResp().FAIL("查询失败");
    }

    @Override
    public BaseResp findcomment() {
        List<Foodcomment> allcomm = foodMapper.findAllcomm();
        if (allcomm.size()!=0)
            return new BaseResp().SUCCESS("查询成功",allcomm,null);
        return new BaseResp().FAIL("查询失败");
    }

    @Override
    public BaseResp findrestone(int faid) {
        List<Foodrestaurant> findrestone = foodMapper.findrestone(faid);
        return new BaseResp().SUCCESS("cg",findrestone,null);
    }

    @Override
    public BaseResp findAllrest() {
        return null;
    }
}
